<template>
  <div id="app">
    <el-row>
      <el-col :span="12">
        <el-button type="primary">新增</el-button>
        <el-button type="warning" @click="deleteAll">批量删除</el-button>
        <el-button type="danger">修改</el-button></el-col
      >
      <el-col :span="12">
        <el-input
          placeholder="请输入内容"
          v-model="input"
          class="input-with-select"
        >
          <el-select v-model="select" slot="prepend" placeholder="请选择">
            <el-option label="餐厅名" value="1"></el-option>
            <el-option label="订单号" value="2"></el-option>
            <el-option label="用户电话" value="3"></el-option>
          </el-select>
          <el-button slot="append" icon="el-icon-search"></el-button>
        </el-input>
      </el-col>
    </el-row>

    <template>
      <el-table
        :data="tableData"
        height="450"
        style="width: 100%; margin-top: 15px"
        @selection-change="handleSelectionChange"
      >
        <el-table-column align="center" type="selection" width="55">
        </el-table-column>
        <el-table-column align="center" type="index" width="55" label="Id">
        </el-table-column>
        <el-table-column align="center" prop="title" label="标题" width="120">
        </el-table-column>
        <el-table-column
          align="center"
          prop="content"
          label="内容"
          style="height: 20px; overflow: hidden"
        >
        </el-table-column>
        <el-table-column
          align="center"
          fixed
          prop="date"
          label="日期"
          width="150"
        >
        </el-table-column>
        <el-table-column align="center" prop="author" label="作者" width="120">
        </el-table-column>
        <el-table-column align="center" prop="type" label="类型" width="150">
        </el-table-column>
        <el-table-column align="center" fixed="right" label="操作" width="100">
          <template slot-scope="scope">
            <el-button
              @click="handleClick(scope.row.id)"
              type="text"
              size="small"
              >删除</el-button
            >
            <el-button type="text" size="small">修改</el-button>
          </template>
        </el-table-column>
      </el-table>
    </template>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="page.currerPage"
      :page-sizes="[1, 2, 3, 4]"
      :page-size="page.PageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="page.total"
    >
    </el-pagination>

    <!-- <el-drawer title="新增" :visible.sync="drawer" :direction="'rtl'">
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="标题">
          <el-input v-model="form.title"></el-input>
        </el-form-item>
        <el-form-item label="内容">
          <el-input v-model="form.content"></el-input>
        </el-form-item>
        <el-form-item label="作者">
          <el-input v-model="form.author" disabled></el-input>
        </el-form-item>
        <el-form-item label="类别管理">
          <el-select v-model="form.cid" placeholder="请选择类别管理">
            <el-option
              v-for="(v, i) in options"
              :key="i"
              :label="v.name"
              :value="v.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="用时">
          <el-select v-model="form.time" placeholder="请选择时间">
            <el-option label="一分钟" value="1"></el-option>
            <el-option label="两分钟" value="2"></el-option>
            <el-option label="三分钟" value="3"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">确认</el-button>
          <el-button>取消</el-button>
        </el-form-item>
      </el-form>
    </el-drawer> -->
  </div>
</template>

<script>
import { mapState, mapActions, mapMutations } from "vuex";
export default {
  layout: "main",
  data() {
    return {
      input: "",
      select: "",
      multipleSelection: [],
    };
  },
  mounted() {
    this.getMsbd();
  },

  methods: {
    ...mapActions("msbd", ["getMsbd", "deleteMsbd"]),
    ...mapMutations("msbd", ["MSBD_PAGE", "MSBD_SIZE"]),
    //分页
    async handleSizeChange(row) {
      await this.MSBD_SIZE(row);
      this.getMsbd();
    },
    async handleCurrentChange(row) {
      await this.MSBD_PAGE(row);
      this.getMsbd();
    },
    //删除
    handleClick(id) {
      if (confirm("确认删除吗")) {
        this.deleteMsbd(id);
      }
    },

    //多删
    handleSelectionChange(id) {
      this.multipleSelection = id.map((val) => {
        return val.id;
      });
    },
    deleteAll() {
      if (this.multipleSelection.length == "") {
        alert("请选择需要数据");
        return;
      } else {
        if (confirm("确认删除吗")) {
          this.deleteMsbd(JSON.parse(JSON.stringify(this.multipleSelection)).join(',') );
        }
      }
    },

    
  },

  computed: {
    ...mapState("msbd", ["tableData", "page"]),
  },
};
</script>

<style scoped>
/deep/.el-table .cell {
  height: 80px;
  overflow: auto;
}
</style>